package cst.neu.yuejian_31.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.util.List;

import cst.neu.yuejian_31.Common.Constant;
import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.adapter.CcourseAdapter;
import cst.neu.yuejian_31.adapter.PopularityAdapter;
import cst.neu.yuejian_31.bean.CcourseBean;
import cst.neu.yuejian_31.iface.CcourseListener;
import cst.neu.yuejian_31.model.CcourseModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class CCourseFragment extends Fragment {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private CcourseAdapter ccourseAdapter;
    private List<CcourseBean> list=null;
    private View view=null;
    private String clubId,pic;
    private Context context;
    private ImageView clubPic;

    CcourseListener ccourseListener=new CcourseListener() {
        @Override
        public void onResponse(List<CcourseBean> ccourseBean) {
            list=ccourseBean;
            ccourseAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {

            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
        }
    };

    public CCourseFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_ccourse, container, false);
        clubId=getActivity().getIntent().getStringExtra("club_id");
        CcourseModel model=new CcourseModel();
        model.getCcourse(clubId,ccourseListener);
        Intent intent =getActivity().getIntent();
        pic=intent.getStringExtra("club_headpic");
        clubPic= (ImageView) view.findViewById(R.id.imageView_club_cc);
        Picasso.with(getActivity()).load(Constant.CLUB_URL+pic).into(clubPic);
        init();
        return view;
    }

    private void init() {
        context=this.getActivity();
        recyclerView= (RecyclerView) view.findViewById(R.id.recyclerView_ccourse);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        ccourseAdapter=new CcourseAdapter(context);
        ccourseAdapter.setList(list);
        recyclerView.setAdapter(ccourseAdapter);
// 设置Item之间间隔样式
        recyclerView .addItemDecoration(new DividerItemDecoration(context,LinearLayoutManager.VERTICAL));
    }
}
